﻿using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfVideo {
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void openBtn_Click(object sender, RoutedEventArgs e) {
            ShellContainer selectedFolder = null;
            selectedFolder = KnownFolders.Desktop as ShellContainer;
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();
            cfd.InitialDirectoryShellContainer = selectedFolder;
            cfd.EnsureReadOnly = true;
            cfd.Filters.Add(new CommonFileDialogFilter("MP3 Files", "*.mp4"));
            cfd.Filters.Add(new CommonFileDialogFilter("WMV Files", "*.wmv"));
            cfd.Filters.Add(new CommonFileDialogFilter("AVI Files", "*.avi"));
            cfd.Filters.Add(new CommonFileDialogFilter("MP3 Files", "*.mp3"));

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok) {
                mediaElement.Source = new Uri(cfd.FileName, UriKind.Relative);
                playBtn.IsEnabled = true;
            }
        }

        private void PlayerPause() {
            //SetPlayer(true);
            if (playBtn.Content.ToString() == "Play") {
                mediaElement.Play();
                playBtn.Content = "Pause";
                mediaElement.ToolTip = "Click to Pause";
            } else {
                mediaElement.Pause();
                playBtn.Content = "Play";
                mediaElement.ToolTip = "Click to Play";
            }
        }

        private void playBtn_Click(object sender, RoutedEventArgs e) {
            PlayerPause();
        }

        private void mediaElement_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
            PlayerPause();
        }

        private void backBtn_Click(object sender, RoutedEventArgs e) {
            mediaElement.Position = mediaElement.Position - TimeSpan.FromSeconds(10);
        }

        private void forwardBtn_Click(object sender, RoutedEventArgs e) {
            mediaElement.Position = mediaElement.Position + TimeSpan.FromSeconds(10);
        }

        private void StopBtn_Click(object sender, RoutedEventArgs e) {

        }
    }
}
